package ru.susu.algebra.chartable.degree;

import java.util.ArrayList;
import java.util.Random;

import junit.framework.TestCase;

import org.junit.Test;

import ru.susu.algebra.partition.Partition;
import ru.susu.algebra.partition.PartitionsFactory;

/**
 * @author akargapolov
 * @since: 06.09.2009
 */
public class TestDegrees extends TestCase
{
	public TestDegrees(String testName)
	{
		super(testName);
	}

	@Test
	public void testDegreeMethods()
	{
		System.out.println("ru.susu.algebra.chartable.degree.TestDegrees.testDegreeMethods");
		int num = 100;
		IDegreeCalculator hooks = new HooksDegreeCalculator();
		IDegreeCalculator knut = new KnutDegreeCalculator();
		while (num-- > 0)
		{
			Partition p = this.getRandomPartition();
			assertEquals(hooks.calculateDegree(p), knut.calculateDegree(p));
		}
	}

	private Partition getRandomPartition()
	{
		Random rand = new Random();
		int n = rand.nextInt() % 51 + 10;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while (n > 0)
		{
			int t = rand.nextInt(n) + 1;
			n -= t;
			list.add(t);
		}
		return PartitionsFactory.createPartition(list.toArray(new Integer[list.size()]));
	}
}
